<script type="text/javascript"><!--//--><![CDATA[//><!--

	// Function for reload City option, depend on selected Province
	var f_set_combo_city_code = function(){
		var ls_province_code	= $('#province_code').val();
		var ls_city_code		= '<?php echo $data['city_code']; ?>';
		
		$('#city_code').setCombo({ 
			data: gs_path+'/combo/swcity/?as_province_code='+ls_province_code, 
			value: ls_city_code 
		});
	};
	
    $(document).ready(function() {
        // Setup Form
		$('#form_master').setupForm([
            { name: 'pk_master', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'field1', type: 'text', size: 'long', maxlength: 100, noempty:true },
			{ name: 'field2', type: 'date' },
			{ name: 'field3', type: 'date' },
			{ name: 'field4', type: 'numeric', precision:2 },
			{ name: 'field5', type: 'numeric', precision:5 },
			{ name: 'field6', type: 'textarea', size:'medium', rows:3 },
			{ name: 'field7', type: 'text', size: 'long', maxlength: 100 },
			{ name: 'ref_key_combo', size: 'long', data:<?php echo json_encode($arr_reference); ?> },
			{ name: 'ref_key_lov', type: 'lov', size: 'short',
				onClearButton:function(){
					$(this).setval(''); 
					$('#ref_name_lov').setval(''); 
				},
				onActionButton:function(){ 
					LOVCoreSampleReference({ onSelect:function(row){ 
						$('#ref_key_lov').setval(row.ref_key); 
						$('#ref_name_lov').setval(row.ref_name); 
					} }); 
				}
			},
			{ name: 'ref_name_lov', type: 'text', size: '24', readonly:true },
			{ name: 'province_code', size: 'long', data:<?php echo json_encode($arr_province); ?>, onChange:f_set_combo_city_code },
			{ name: 'city_code', size: 'long', data:[] }
        ], <?php echo json_encode($data); ?>);
        
		f_set_combo_city_code();
		
        <?php if($mode=="edit"){ ?>
        $('#pk_master').readonly();
        <?php } ?>
		
		// Set Action Button
		var buttons = [{ label: 'Save', icon: 'save', onclick: function() { 
							$('#form_master').submitForm(	'/'+controller+'/ajax_post', 
															{	detail:[	{ table: 'dtl_sample1', field:['index_no','tgl_field','keterangan']},
																			{ table: 'dtl_sample2', field:['index_no','ref_key_combo','ref_key_lov','jumlah','keterangan']}
																		], 
																onComplete : function(data){ eval('oData = '+data); loadPage('/'+controller+'/edit/?pk_master='+(oData.genid!='' ? oData.genid : $('#pk_master').getval())); }
															} 
														); 
						}},
					   { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/Index'); } }];
		setAction(buttons);
		
		// Create Tab
		$('#tt').tabs({ border:false });  
		
		// Focus at First Object
		$('#form_master').focusFirst();
    });
//--><!]]></script>

<div id="form_master_message" style="display:none;"></div>

<table class="tb_form" style="display:none;" cellpadding="0" cellspacing="0">
<tr>
    <td class="label">Primary Key</td>
    <td><input id="pk_master" /></td>
    <td class="label">Field 1</td>
    <td><input id="field1" /></td>
</tr>
<tr>
    <td class="label">Field 2 - Field 3</td>
    <td><input id="field2" />- &nbsp; <input id="field3" /></td>
    <td class="label">Field 4</td>
    <td><input id="field4" /></td>
</tr>
<tr>
    <td class="label">Field 5</td>
    <td><input id="field5" /></td>
    <td class="label" rowspan="2">Field 6</td>
    <td rowspan="2"><input id="field6" /></td>
</tr>
<tr>
    <td class="label">Field 7</td>
    <td><input id="field7" /></td>
</tr>
<tr>
    <td class="label">Combo Ref</td>
    <td><input id="ref_key_combo" /></td>
    <td class="label">Province</td>
    <td><input id="province_code" /></td>
</tr>
<tr>
    <td class="label">LOV Ref</td>
    <td><input id="ref_key_lov" /><input id="ref_name_lov" /></td>
    <td class="label">City</td>
    <td><input id="city_code" /></td>
</tr>
</table>

<div id="tt" class="easyui-tabs" style="min-height:400px;">  
	<div title="Detail 1" style="overflow:auto;padding:10px;">  
    	<?php require_once('formdtl_sample1.php'); ?>
    </div>
    
    <div title="Detail 2" style="overflow:auto;padding:10px;">  
    	<?php require_once('formdtl_sample2.php'); ?>
    </div>
    
    <div title="Detail File" style="overflow:auto;padding:10px;">  
    	<?php require_once('formdtl_file.php'); ?>
    </div>
</div>